var app = getApp()

Page({
  data: {
    step: [{
      val: 1,
      name: '1步'
    }, {
      val: 2,
      name: '2步',
      checked: true
    }],
    op_str: [{
      value: 1,
      name: '+',
      checked: true
    }, {
      value: 2,
      name: '-',
      checked: true
    }, {
      value: 3,
      name: '×'
    }, {
      value: 4,
      name: '÷'
    }],
    templateList:[]
  },
  onLoad: function () {
    this.loadTemplateID();
    if (!app.checkIsLogin()) {
      app.showError('很抱歉，您还没有登录', function () {
        wx.navigateTo({
          url: '/pages/login/login',
        })
      });
      return false;
    }
  },
  onShow: function () {

  },
  loadTemplateID(){
    var that =this;
    app._get('user/wx_message_template','',function (res) {
      // console.log(res.data)
        that.setData({
          templateList:res.data
        })
    });
  },
  createMath(e) {
    var that = this;

    if (e.detail.value.op_str.length == 0) {
      wx.showToast({
        title: '请选择运算符',
        duration: 2000,
        icon: 'error'
      })
      return false;
    }
    if (e.detail.value.step == '') {
      wx.showToast({
        title: '请选择几步运算',
        duration: 2000,
        icon: 'error'
      })
      return false;
    }
    wx.requestSubscribeMessage({
      // tmplIds: ['sNrOvfxKncoCjKZ-KM77XfAcrGdmXjR2l-hjfWTx38w'],
      tmplIds: that.data.templateList,
      success(res) {
        // console.log(1111,res['sNrOvfxKncoCjKZ-KM77XV6y8vrTUgWK98wwOV2L4S4'])
        // 跳转到题目页面

        var param = '?pp=' + JSON.stringify(e.detail.value);

        wx.redirectTo({
          url: '/pages/study/index' + param,
        })
      }
    })


    // console.log(that.data.first_op_min)
  },
  sexchange(e) {
    var values = e.detail.value
    this.setData({
      'op_str_val': values
    })
    // console.log(this.data.op_str_val)
  },
  stepchange(e) {
    var values = e.detail.value
    this.setData({
      'step_val': values
    })
  }
})